package edu.ccut.saturn.basecomponent.database;

import java.sql.Connection;
import java.util.List;

import edu.ccut.saturn.component.SaturnComponentException;
import edu.ccut.saturn.component.SaturnData;

/**
 * SaturnSQL处理器实现
 * 
 * @author tony
 * 
 */
public class SaturnSQLHandler {

	private SaturnSQLHandler() {

	}

	public static int executeUpdate(ISaturnSQL saturnSQL, Connection connection)
			throws SaturnComponentException {
		
		ISaturnSQLHandler handler = SaturnSQLHandlerFactory.getSaturnSQLHandler(
				saturnSQL.getOperationType(), saturnSQL.getDBType());

		if (handler != null) {
			return handler.executeUpdate(saturnSQL, connection);
		}

		return -1;
	}

	public static List<SaturnData> executeQuery(ISaturnSQL saturnSQL,
			Connection connection) throws SaturnComponentException {
		
		ISaturnSQLHandler handler = SaturnSQLHandlerFactory
				.getSaturnSQLHandler(saturnSQL.getOperationType(), saturnSQL.getDBType());

		if (handler != null) {
			return handler.executeQuery(saturnSQL, connection);
		}

		return null;
	}
}
